//------------------------------------------------------------------------------
// <copyright file="IRpcStringSocket.h" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

#pragma once

#include <functional>

namespace Microsoft { namespace Internal { namespace GamesTest { namespace Rpc { namespace Server
{
	/// <summary>
	/// This interface defines a socket that can send and receive strings.
	/// </summary>
	class IRpcStringSocket
	{
	public:
		typedef std::function<void (IRpcStringSocket* socket, std::wstring data)> DataReceivedCallback;
		typedef std::function<void (IRpcStringSocket* socket)> SocketDisconnectedCallback;

		/// <summary>
		/// Gets the IpAddress of the client that this socket connects to.
		/// </summary>
		/// <remarks>At the moment this method is only used for debug spew when errors occur.</remarks>
		virtual std::wstring GetIpAddress() = 0;

		/// <summary>
		/// Send the string data back to the connected client.
		/// </summary>
		virtual GAMESTEST_ANNOTATE_HRESULT_METHOD HRESULT SendData(const std::wstring& data) = 0;

		/// <summary>
		/// Start listening for incoming strings and invoke the given callback when they arrive.
		/// </summary>
		/// <param name="dataReceivedCallback">A function to be called when a string has been received by the socket.</param>
		/// <param name="clientDisconnectedCallback">A function to be called when the underlying socket has disconnected.</param>
		virtual HRESULT StartListening(DataReceivedCallback dataReceivedCallback, SocketDisconnectedCallback clientDisconnectedCallback) = 0;

		virtual ~IRpcStringSocket() { };
	};

}}}}}